//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "DPPdData.h"
#include "DModule.h"

//---------------------------------------------------------------------------
#pragma package( smart_init )
#pragma link "DialPad"
#pragma link "PHDS"
#pragma link "PHEdit"
#pragma link "PHLabel"
#pragma link "DIALPAD"
#pragma resource "*.dfm"
TDPPdData1*  DPPdData1;

//---------------------------------------------------------------------------
__fastcall TDPPdData1::TDPPdData1( TComponent*  Owner ) : TDiPad( Owner )
{
  Data = 0;
  Titulo = "";
  AceitaBranco = false;
}

//---------------------------------------------------------------------------
void __fastcall TDPPdData1::BitBtn1Click( TObject*  Sender )
{
  Close();
}

//---------------------------------------------------------------------------
void __fastcall TDPPdData1::FormCloseQuery( TObject*  Sender, bool&  CanClose )
{
    try
     {
      PHDS1->Tabela = DM->TBGeral;
      GravaDiPad( PHDS1 );
     }
    catch (Exception &E)
     {
      ShowMensagem(E.Message);
     }


    if( ( int ) PHDS1->GV( Campo, 0 ) == 0 && !AceitaBranco )
     {
      CanClose = false;
      PHDS1->EnviaFoco( Campo, 0, NULL );
      throw Exception( PHLabel1->Caption );
     }

    Data = ( int ) PHDS1->GV( Campo, 0 );
}

//---------------------------------------------------------------------------
void __fastcall TDPPdData1::FormShow( TObject*  Sender )
{
  PHLabel1->Caption = PHDS1->Tabela->CamposDef->Items[PHDS1->CodCampoTabela( Campo )]->Titulo;
  if( Titulo != "" )
   {
    PHLabel1->Caption = Titulo;
   }

  if( Width < PHLabel1->Canvas->TextWidth( PHLabel1->Caption ) + 20 )
   {
    Width = PHLabel1->Canvas->TextWidth( PHLabel1->Caption ) + 20;
   }

  PHEdit1->PHDSCampo = Campo;
  TDiPad::FormShow( Sender );
  if( Data || Titulo != "" )
   {
    PHDS1->Edit();
    if( Data )
     {
      PHDS1->SV( Campo, 0, Data );
     }
    else
     {
      PHDS1->SV( Campo, 0, "" );
     }
   }
}

//---------------------------------------------------------------------------
void __fastcall TDPPdData1::Chama( AnsiString Titulo, AnsiString NomeCampo )
{
  Campo = NomeCampo.c_str();
  DPPdData1->Caption = Titulo.c_str();
  ShowModal();
}

//---------------------------------------------------------------------------

